// Form 组件样式

.viking-form {
  font-size: $font-size-base;
  line-height: $line-height-base;
  color: $body-color;

  // 垂直布局
  &.viking-form-vertical {
    .viking-form-item {
      margin-bottom: $form-item-margin-bottom;

      .viking-form-item-label {
        display: block;
        margin-bottom: $form-item-label-margin-bottom;
        padding: 0;
        line-height: $line-height-base;
        white-space: nowrap;
        text-align: left;

        label {
          font-size: $font-size-base;
          color: $form-item-label-color;
        }
      }

      .viking-form-item-control {
        display: block;
      }
    }
  }

  // 水平布局
  &.viking-form-horizontal {
    .viking-form-item {
      display: flex;
      margin-bottom: $form-item-margin-bottom;

      .viking-form-item-label {
        flex: 0 0 auto;
        padding: $form-item-label-padding;
        line-height: $input-height-base;
        white-space: nowrap;
        text-align: right;

        label {
          font-size: $font-size-base;
          color: $form-item-label-color;
        }
      }

      .viking-form-item-control {
        flex: 1 1 auto;
        min-width: 0;
      }
    }
  }

  // 内联布局
  &.viking-form-inline {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;

    .viking-form-item {
      display: inline-flex;
      align-items: center;
      margin-right: $form-item-margin-right;
      margin-bottom: $form-item-margin-bottom-inline;

      .viking-form-item-label {
        flex: 0 0 auto;
        margin-right: $form-item-label-margin-right;
        padding: 0;
        line-height: $input-height-base;
        white-space: nowrap;

        label {
          font-size: $font-size-base;
          color: $form-item-label-color;
        }
      }

      .viking-form-item-control {
        flex: 1 1 auto;
        min-width: 0;
      }
    }
  }
}

// Form Item 样式
.viking-form-item {
  position: relative;

  // 标签样式
  .viking-form-item-label {
    label {
      position: relative;
      display: inline-block;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      vertical-align: middle;
      cursor: default;
    }
  }

  // 必填标记
  .viking-form-item-required {
    display: inline-block;
    margin-right: 4px;
    color: $danger;
    font-size: $font-size-base;
    font-family: inherit;
    line-height: 1;
    content: "*";

    &::before {
      display: inline-block;
      margin-right: 4px;
      color: $danger;
      font-size: $font-size-base;
      font-family: inherit;
      line-height: 1;
      content: "*";
    }
  }

  // 控件容器
  .viking-form-item-control {
    position: relative;
    line-height: $input-height-base;

    .viking-form-item-control-input {
      position: relative;
      display: inline-block;
      width: 100%;
      min-height: $input-height-base;
      padding: 0;
      color: $input-color;
      font-size: $font-size-base;
      line-height: $line-height-base;
      background-color: $input-bg;
      background-image: none;
      border: $input-border-width solid $input-border-color;
      border-radius: $input-border-radius;
      transition: $input-transition;

      // 输入框样式继承
      input,
      textarea,
      select {
        width: 100%;
        border: none;
        outline: none;
        background: transparent;
        font-size: inherit;
        color: inherit;
        line-height: inherit;
        padding: $input-padding-y $input-padding-x;

        &:focus {
          box-shadow: none;
        }
      }

      // 聚焦状态
      &:focus-within {
        border-color: $primary;
        box-shadow: $input-focus-box-shadow;
      }
    }
  }

  // 错误状态
  &.viking-form-item-has-error {
    .viking-form-item-control-input {
      border-color: $danger;

      &:focus-within {
        border-color: $danger;
        box-shadow: 0 0 0 2px rgba($danger, 0.2);
      }
    }

    .viking-form-item-label label {
      color: $danger;
    }
  }

  // 验证中状态
  &.viking-form-item-validating {
    .viking-form-item-control-input {
      &::after {
        position: absolute;
        top: 50%;
        right: 8px;
        z-index: 1;
        width: 14px;
        height: 14px;
        margin-top: -7px;
        color: $primary;
        line-height: 1;
        text-align: center;
        content: "";
        border: 2px solid transparent;
        border-top-color: $primary;
        border-radius: 50%;
        animation: viking-spin 1s linear infinite;
      }
    }
  }

  // 错误信息
  .viking-form-item-error {
    margin-top: 4px;
    color: $danger;
    font-size: $font-size-sm;
    line-height: $line-height-sm;
    transition: color 0.3s ease;
  }

  // 帮助文本
  .viking-form-item-help {
    margin-top: 4px;
    color: $text-muted;
    font-size: $font-size-sm;
    line-height: $line-height-sm;
    transition: color 0.3s ease;
  }

  // 额外信息
  .viking-form-item-extra {
    margin-top: 4px;
    color: $text-muted;
    font-size: $font-size-sm;
    line-height: $line-height-sm;
  }
}

// 旋转动画
@keyframes viking-spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

// 响应式设计
@media (max-width: 575.98px) {
  .viking-form {
    &.viking-form-horizontal {
      .viking-form-item {
        flex-direction: column;

        .viking-form-item-label {
          text-align: left;
          padding-bottom: 4px;
        }
      }
    }

    &.viking-form-inline {
      .viking-form-item {
        display: flex;
        flex-direction: column;
        width: 100%;
        margin-right: 0;

        .viking-form-item-label {
          text-align: left;
          margin-right: 0;
          margin-bottom: 4px;
        }
      }
    }
  }
}
